package reno.market.mainmarket.warframemarket.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reno.market.mainmarket.common.JSONUtils;
import reno.market.mainmarket.common.ResponseMO;
import reno.market.mainmarket.warframemarket.mo.WarframeMarketMO;
import reno.market.mainmarket.warframemarket.service.WarframeMarketService;

import java.util.Map;
import java.util.Vector;

@RestController
public class WarframeMarketController {

    @Autowired
    WarframeMarketService warframeMarketService;

    @RequestMapping(value = "/getWarframeMarket")
    public JSONObject getWarframeMarket(@RequestParam(value = "itemCn") String itemCn) {
        ResponseMO responseMO;
        Map<String, String> queryInfo = warframeMarketService.translateInfo(itemCn);
        Map<String, Vector<WarframeMarketMO>> tradeInfo = warframeMarketService.getTradeInfo(queryInfo);
        responseMO = warframeMarketService.buildResponse(tradeInfo, queryInfo);
        if (responseMO.length()>0) {
            return JSONUtils.success(responseMO);
        } else {
            responseMO.setResponseString0("未查询到相关物品，请检查物品名后重试");
            return JSONUtils.failure(responseMO);
        }
    }
}
